package com.example.home.rubbish.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.rubbish.bean.RcvListBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class NewsClassifyAdapter extends RecyclerView.Adapter<NewsClassifyAdapter.MyHoldy> {
    private Context context;
    private List<RcvListBean.RowsBean> list;
    private View view;

    public NewsClassifyAdapter(Context context, List<RcvListBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public NewsClassifyAdapter.MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充视图
        view = LayoutInflater.from(context).inflate(R.layout.item_help, null);
        return new NewsClassifyAdapter.MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NewsClassifyAdapter.MyHoldy holder, int position) {
        Glide.with(context).load(ip+list.get(position).getImgUrl()).into(holder.news_img);
        holder.news_text.setText(list.get(position).getName());
    }


    @Override
    public int getItemCount() {

        return list == null ? 0 : 20;

    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private LinearLayout rootView;
        private ImageView news_img;
        private TextView news_text;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);
            news_img = itemView.findViewById(R.id.news_img);
            news_text = itemView.findViewById(R.id.news_text);
        }
    }
}

